$(document).ready(function () {

    //点击返回
    $(".go-back").click(function () {
        var url = $(this).attr("url");
        console.log(url);
        window.location = url;
    });


    //点击登陆
    $('.login_btn').click(function () {
        var mobile = $('#login_phone').val();
        var password = $("#login_pass").val();
        if (mobile == '') {
            layer.msg('手机号不能为空');
            return;
        }
        if (!isPhoneNumber(mobile)) {
            layer.msg('手机号格式不正确');
            return;
        }
        if (password == '') {
            layer.msg('密码不能为空');
            return;
        }
        $.post("/index/user/login", { mobile: mobile, password: password }, function (ret) {
            if (ret.code == 1) {
                layer.msg(ret.msg, { icon: 1, time: 1000 }, function () {
                    localStorage.setItem('u_access', ret.u_access);
                    // window.location.href = "/index/user/index";
                    if(ret.data.expert_level==0){
                        window.location.href = "/index/expert/index";
                    }else{
                        window.location.href = "/index/user/index";
                    }
                });
            } else {
                layer.msg(ret.msg);
            }

        }, 'json');

    });


});


function isNumber(obj) {
    return !isNaN(parseFloat(obj)) && isFinite(obj);
}
function isPhoneNumber(tel) {
    var reg = /^0?1[3|4|5|6|7|8|9][0-9]\d{8}$/;
    return reg.test(tel);
}